package org.example.iris.service.impl;

import org.example.iris.mapper.ApplicationMapper;
import org.example.iris.mapper.StudentMapper;
import org.example.iris.entity.Application;
import org.example.iris.entity.Student;
import org.example.iris.dto.ApplicationInfo;
import org.example.iris.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApplicationServiceImpl implements ApplicationService {

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private ApplicationMapper applicationMapper;

    @Override
    public boolean approveApplication(int applicationId, String status) {
        // 调用 Mapper 更新申请状态
        applicationMapper.updateApplicationStatus(applicationId, status);
        return true; // 假设更新成功返回 true
    }

    /**
     * 获取某个岗位的所有申请ID
     * @param jobId 岗位ID
     * @return 申请ID列表
     */
    @Override
    public List<ApplicationInfo> getApplicationIdsAndStudentIdsByJobId(int jobId) {
        // 调用Mapper查询，返回包含申请ID和学生ID的列表
        return applicationMapper.getApplicationIdsAndStudentIdsByJobId(jobId);
    }

    @Override
    public List<Application> getApplication(Integer userId) {
        Student student = studentMapper.findByUserId(userId);
        Integer studentId = student.getStudentId();
        return applicationMapper.getApplicationByStudentId(studentId);
    }

    @Override
    public void deleteApplication(Integer applicationId) {
        applicationMapper.deleteApplication(applicationId);
    }
}